import asyncio

import semantic_kernel as sk
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
import os

async def run_function(*args):
    return await kernel.invoke(*args)

if __name__ == "__main__":
    os.environ["OPENAI_API_KEY"] = os.environ["OPENAI_API_KEY_ZHIHU"]
    os.environ["OPENAI_BASE_URL"] = os.environ["OPENAI_API_BASE_ZHIHU"]

    kernel = sk.Kernel()
    service = OpenAIChatCompletion(service_id="default",api_key=os.environ.get("OPENAI_API_KEY_ZHIHU"),ai_model_id="gpt-4o")
    kernel.add_service(service=service)

    joke_function = kernel.add_function(plugin_name="MyDemoPlugin",function_name="joke_function",prompt="讲一个笑话")



    result = asyncio.run(kernel.invoke(joke_function))
    print(result)
